<template>
  <div class="department">
    <div class="header">
      <div class="header-1">
        <div class="header-1-1">
          <div class="tou"></div>
          <span>查询条件</span>
        </div>
      </div>
      <el-form
        style="margin-left: 20px"
        size="mini"
        :inline="true"
        :data="formInline"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="员工部门">
          <el-select v-model="formInline.deptId" placeholder="请选择" clearable>
            <el-option
              v-for="(item, index) in dropDownList"
              :key="index"
              :label="item.deptName"
              :value="item.deptId"
            >
            </el-option>
          </el-select>
          <!-- <el-cascader :options="dropDownList" clearable> </el-cascader> -->
        </el-form-item>
        <el-form-item label="员工姓名">
          <el-input
            v-model="formInline.employeeName"
            placeholder="员工姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="员工工号">
          <el-input
            v-model="formInline.employeeLoginId"
            placeholder="员工工号"
          ></el-input>
        </el-form-item>
        <el-form-item label="员工手机号">
          <el-input
            v-model="formInline.employeeMobile"
            placeholder="员工手机号"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            style="color: #fff; width: 80px"
            @click="seachBtn"
            >查询</el-button
          >
          <el-button
            type="primary"
            style="width: 80px; color: #fff"
            @click="reset()"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <div class="hackhome"></div>
      <div class="header-1">
        <div class="tuo">
          <div class="tuo-1">
            <div class="tuo-2"></div>
            <span>员工列表</span>
          </div>
          <div class="tuo-3">
            <el-button
              type="primary"
              style="color: #fff; width: 110px"
              size="mini"
              @click="add((dialogVisible = true))"
              >新增
            </el-button>
          </div>
        </div>
        <!-- 管理员列表 -->
        <div class="table">
          <el-table
            border
            size="mini"
            ref="multipleTable"
            :data="employees"
            :header-cell-style="{
              color: '#fff',
              background: '#6090EC',
              fontSize: '11px',
              fontWeight: 'normal',
            }"
            row-key="index"
            :tree-props="{ children: 'children' }"
          >
            <el-table-column prop="ancestors" label="员工部门">
               <!-- <template slot-scope="scope">
                <template>{{scope.row.ancestors}}</template>
              
               </template> -->
            </el-table-column>
            <el-table-column prop="adminName" label="员工姓名">
            </el-table-column>
            <el-table-column prop="adminNumber" label="员工工号">
            </el-table-column>

            <el-table-column
              prop="adminPhone"
              label="员工手机号"
              width="100"
            >
            </el-table-column>
            <el-table-column prop="adminCard" label="身份证号码" width="100">
            </el-table-column>
            <el-table-column prop="adminSex" label="性别">
             
            </el-table-column>
            <el-table-column prop="adminBirthday" label="生日">
            </el-table-column>
            <el-table-column prop="sysRoleBOList" label="角色">
               <template slot-scope="scope">
              <div v-for="(item, index) in scope.row.sysRoleBOList" :key="index">
                <div>{{ item.roleDescription }}</div>
              </div>
               </template>
            </el-table-column>
            <!-- <el-table-column prop="positionName" label="操作日志" width="80">
            </el-table-column> -->
            <el-table-column prop="isManager" label="是否IVP经理" width="120">
              <!-- <template>{{ (employeeSex = "male" ? "男" : "女") }}</template> -->
              <template slot-scope="scope">
                <template v-if="scope.row.isManager == 'yes'">是</template>
                <template v-if="scope.row.isManager == 'no'">否</template>
              </template>
            </el-table-column>
            <el-table-column prop="userBOS" label="资源数">
                <template slot-scope="scope">
                <template >{{scope.row.userBOS.length}}</template>
                </template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
              <template slot-scope="scope">
                <template>
                  {{ scope.row.status === "no" ? "离职" : "在职" }}
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="操作" width="440">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  style="color: #fff; width: 75px"
                  @click="editjob(scope.row)"
                  >修改
                </el-button>
                <el-button
                  size="mini"
                  @click="getquit(scope.$index, scope.row)"
                  style="background-color: #6090ec; color: #fff; width: 75px"
                  >{{ scope.row.status == "no" ? "入职" : "离职" }}
                </el-button>
                <!-- <el-button
                  type="primary"
                  style="color: #fff; width: 75px"
                  size="mini"
                  @click="password(scope.$index, scope.row)"
                  >重置密码
                </el-button> -->
                <el-button
                  v-if="scope.row.userBOS.length != 0"
                  type="primary"
                  style="color: #fff; width: 75px"
                  size="mini"
                  @click="resourceAllocationbtn(scope.$index, scope.row)"
                  >资源转移
                </el-button>
                <el-button
                  v-if="scope.row.userBOS.length != 0"
                  type="primary"
                  style="color: #fff; width: 75px"
                  size="mini"
                  @click="resourceretrievebtn(scope.row)"
                  >资源回收
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              :current-page="formInline.pageNum"
              :page-size="formInline.pageSize"
              :page-sizes="[10, 20, 30]"
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
              layout="total,prev, pager, next, sizes"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
        <!-- 新增弹窗 -->
        <el-dialog
          title="系统管理-新增"
          :visible.sync="dialogVisible"
          :close-on-click-modal="false"
          width="45%"
        >
          <div class="header-1">
            <div class="header-1-1-1">
              <div class="tou"></div>
              <span>新增</span>
            </div>
          </div>
          <el-form
            size="mini"
            :data="employees"
            :model="ruleForm"
            status-icon
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
          <div class="cen_head">
            <div class="upload_box">
              <div class="upload">请上传员工头像</div>
              <el-upload
                class="avatar-uploader"
                :action="imgHttpUrl"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                list-type="picture-card"
                :on-exceed="handleExceed"
                 :headers="header"
                :data="multipartFile"
              >
                
              <!-- :before-upload="beforeAvatarUpload" -->
                <img v-if="imageUrl" :src="imageUrl"  class="avatar" />
                <i v-else class="el-icon-plus"></i>
              </el-upload>
            </div>
            <!-- <div class="upload_box">
              <div class="upload">请上传员工二维码</div>

            
            </div> -->
          </div>
            <div class="form_item">
              <el-form-item label="员工工号" prop="employeeLoginId">
                <el-input
                  style="width: 150px"
                  v-model="ruleForm.employeeLoginId"
                ></el-input>
              </el-form-item>
              <el-form-item label="员工姓名" prop="employeeName">
                <el-input v-model="ruleForm.employeeName"></el-input>
              </el-form-item>
            </div>
            <div class="form_item">
              <el-form-item label="员工手机号" prop="employeeMobile">
                <el-input
                  style="width: 150px"
                  v-model="ruleForm.employeeMobile"
                ></el-input>
              </el-form-item>
              
              <el-form-item label="员工密码" prop="employeeLoginPwd">
                <el-input
                  type="password"
                  v-model="ruleForm.employeeLoginPwd"
                ></el-input>
              </el-form-item>
              
            </div>
            <div class="form_item">
              <el-form-item label="员工部门" prop="deptId">
                <!-- <el-input v-model="ruleForm.deptId" autocomplete=""></el-input> -->
                <el-select
                  v-model="ruleForm.deptId"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dropDownList"
                    :key="index"
                    :label="item.deptName"
                    :value="item.deptId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="员工角色">
                <el-select
                  multiple
                  filterable
                  style="width: 150px"
                  v-model="ruleForm.positionId"
                  placeholder="员工角色"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in positionNameDataList"
                    :key="index"
                    :label="item.roleName"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
             
            </div>
            <div class="form_item">
              <el-form-item label="员工性别">
                <el-radio-group
                  style="width: 150px"
                  v-model="ruleForm.employeeSex"
                >
                  <el-radio label="true">男</el-radio>
                  <el-radio label="false">女</el-radio>
                </el-radio-group>
              </el-form-item>
               <el-form-item label="身份证号" prop="employeeIdno">
                <el-input v-model="ruleForm.employeeIdno"></el-input>
              </el-form-item>
             
            </div>
            <div class="form_item">
              <el-form-item label="是否使用">
                <el-radio-group style="width: 150px" v-model="ruleForm.isused">
                  <el-radio label="yes">是</el-radio>
                  <el-radio label="no">否</el-radio>
                </el-radio-group>
              </el-form-item>
 <el-form-item label="生日" prop="employeeBirthday">
                <!-- <el-input v-model="ruleForm.employeeBirthday"></el-input> -->
                <!-- 日期选择器 -->
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  style="width: 180px"
                  v-model="ruleForm.employeeBirthday"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div style="display: flex">
              <el-form-item label="是否vip经理">
                <el-radio-group v-model="ruleForm.manager">
                  <el-radio label="yes">是</el-radio>
                  <el-radio label="no">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <!-- <el-form-item label="是否供应商">
                <el-radio-group v-model="ruleForm.gongyings">
                  <el-radio label="true">是</el-radio>
                  <el-radio label="false">否</el-radio>
                </el-radio-group>
              </el-form-item>
               -->
            </div>
            <!-- <div class="form_item" v-if="ruleForm.gongyings == 'true'">
              <el-form-item label="选择供应商">
                <el-select
                  style="width: 150px"
                  v-model="ruleForm.supplierId"
                  placeholder="选择供应商"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in gyslist1"
                    :key="index"
                    :label="item.supplierName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div> -->
            <div class="form_item" v-if="ruleForm.manager == 'yes'">
              <el-form-item label="VIP级别">
                <el-select
                  style="width: 150px"
                  v-model="ruleForm.resourcelevel"
                  :disabled="ruleForm.manager != 'yes'"
                  placeholder="vip级别"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in viplevelList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="最大上限" prop="resourcemaxlimitnum">
                <el-input
                  :disabled="ruleForm.manager != 'yes'"
                  v-model="ruleForm.resourcemaxlimitnum"
                >
                </el-input>
              </el-form-item>
           
            </div>
            <div class="form_item" v-if="ruleForm.manager == 'yes'">
              <el-form-item label="昵称" prop="othername">
                <el-input
                  :disabled="ruleForm.manager != 'yes'"
                  v-model="ruleForm.othername"
                ></el-input>
              </el-form-item>
              <el-form-item label="VIP经理电话" prop="othername">
                <el-input
                  :disabled="ruleForm.manager != 'yes'"
                  v-model="ruleForm.managerPhone"
                ></el-input>
              </el-form-item>
            </div>
             <div class="form_item" v-if="ruleForm.manager == 'yes'">
                <el-form-item label="企业微信" >
                <!-- <el-input
                  :disabled="ruleForm.manager != 'true'"
                  v-model="ruleForm.viperweima"
                >
                </el-input> -->
                <!--  -->
                  <el-upload
                class="avatar-uploader"
                :action="imgHttpUrl"
                :show-file-list="false"
                :on-success="handleAvatarSuccesswe"
                list-type="picture-card"
                :on-exceed="handleExceed"
                  :headers="header"
                :data="multipartFile"
              >
                <!-- :before-upload="beforeAvatarUpload" -->

                <img v-if="weChatQrCode" :src="weChatQrCode" />
                <i v-else class="el-icon-plus"></i>
              </el-upload>
              </el-form-item>
            </div>
            <div class="form_item">
              <el-form-item label="备注" prop="employeeMemo">
                <el-input style="width: 400px" v-model="ruleForm.employeeMemo">
                </el-input>
              </el-form-item>
            </div>
            <el-form-item>
              <el-button
                style="background-color: #f6b23e; color: #fff; width: 110px"
                @click="RegulaNew"
                >确认
              </el-button>
              <el-button
                type="primar"
                style="width: 110px"
                @click="dialogVisible = false"
                >取消
              </el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
        <!-- 修改员工 -->
        <el-dialog
          title="系统管理-修改员工信息"
          :visible.sync="editjobs"
          :close-on-click-modal="false"
          width="48%"
        >
          <div class="header-1">
            <div class="header-1-1-1">
              <div class="tou"></div>
              <span>修改员工信息</span>
            </div>
          </div>
          <el-form
            size="mini"
            :data="employees"
            :model="ruleFormd"
            status-icon
            ref="ruleFormd"
            label-width="100px"
            class="demo-ruleForm"
          >
            <div class="cen_head">
              <div class="upload_box">
              <div class="upload">请上传头像</div>
              <el-upload
                class="avatar-uploader"
                :show-file-list="false"
                :action="imgHttpUrl"
                :on-success="handleAvatarSuccessedit"
                list-type="picture-card"
                :on-exceed="handleExceed"
                  :headers="header"
                :data="multipartFile"
              >
                <!-- :before-upload="beforeAvatarUpload" -->

              <img v-if="ruleFormd.updateimageUrl" :src="ruleFormd.imageUrl"/>
                <i v-else class="el-icon-plus"></i>
                <!-- <i class="el-icon-plus avatar-uploader-icon"></i> -->
              </el-upload>
              <!-- <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="" />
              </el-dialog> -->
            </div>
            <!-- <div class="upload_box">
              <div class="upload">请上传员工二维码</div>
          
            </div> -->
            </div>
            <div class="form_item">
              <el-form-item label="员工工号" prop="employeeLoginId">
                <el-input
                  style="width: 150px"
                  v-model="ruleFormd.employeeLoginId"
                ></el-input>
              </el-form-item>
              <el-form-item label="员工姓名" prop="employeeName">
                <el-input v-model="ruleFormd.employeeName"></el-input>
              </el-form-item>
            </div>
            <div class="form_item">
              <el-form-item label="员工手机号" prop="employeeMobile">
                <el-input
                  style="width: 150px"
                  v-model="ruleFormd.employeeMobile"
                ></el-input>
              </el-form-item>  <el-form-item label="员工密码" prop="employeeLoginPwd">
                <el-input
                  type="password"
                  v-model="ruleFormd.employeeLoginPwd"
                ></el-input>
              </el-form-item>
              
            </div>
            <div class="form_item">
              <el-form-item label="员工部门" prop="deptName">
                <!-- <el-input
                  v-model="ruleFormd.deptName"
                  autocomplete=""
                ></el-input> -->
                <!-- 员工部门 -->
                <el-select
                  v-model="ruleFormd.deptId"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in dropDownList"
                    :key="index"
                    :label="item.deptName"
                    :value="item.deptId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="员工角色">
                <el-select
                  multiple
                  filterable
                  style="width: 150px"
                  v-model="ruleFormd.positionId"
                  placeholder="员工角色"
                  clearable
                  
                >
                  <el-option
                    v-for="(item, index) in positionNameDataList"
                    :key="index"
                    :label="item.roleName"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              
            </div>
            <div class="form_item">
              <el-form-item label="身份证号" prop="employeeIdno">
                <el-input v-model="ruleFormd.employeeIdno"></el-input>
              </el-form-item>
              <el-form-item label="员工性别">
                <el-radio-group
                  style="width: 150px"
                  v-model="ruleFormd.employeeSex"
                >
                  <el-radio label="男">男</el-radio>
                  <el-radio label="女">女</el-radio>
                </el-radio-group>
              </el-form-item>
             
            </div>
            <div class="form_item">
              <el-form-item label="是否使用">
                <el-radio-group style="width: 150px" v-model="ruleFormd.isused">
                  <el-radio label="yes">是</el-radio>
                  <el-radio label="no">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="生日" prop="employeeBirthday">
                <!-- 日期选择器 -->
                <el-date-picker
                  style="width: 180px"
                  v-model="ruleFormd.employeeBirthday"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <el-form-item
              label="是否vip经理"
              prop="manager"
            >
              <!-- v-if="ruleFormd.supplierId == 'null'" -->

              <el-radio-group v-model="ruleFormd.manager">
                <el-radio label="yes">是</el-radio>
                <el-radio label="no">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <div class="form_item" v-if="ruleFormd.manager =='yes'">
              <el-form-item label="VIP级别">
                <el-select
                  style="width: 150px"
                  v-model="ruleFormd.resourcelevel"
                  placeholder="vip级别"
                >
                  <el-option label="初级" value="初级"></el-option>
                  <el-option label="中级" value="中级"></el-option>
                  <el-option label="高级" value="高级"></el-option>
                  <el-option label="资深" value="资深"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="最大上限" prop="resourcemaxlimitnum">
                <el-input v-model="ruleFormd.resourcemaxlimitnum"> </el-input>
              </el-form-item>
            </div>
            <div class="form_item" v-if="ruleFormd.manager =='yes'">
              <el-form-item label="昵称" prop="othername">
                <el-input v-model="ruleFormd.othername"></el-input>
              </el-form-item>
              <el-form-item label="vip经理电话" prop="resourcemaxlimitnum">
                <el-input v-model="ruleFormd.managerPhone"> </el-input>
              </el-form-item>
            </div>
             <div class="form_item" v-if="ruleFormd.manager =='yes'">
                <el-form-item label="企业微信" >
                <!-- <el-input
                  :disabled="ruleForm.manager != 'true'"
                  v-model="ruleForm.viperweima"
                >
                </el-input> -->
                   <el-upload
                class="avatar-uploader"
                :show-file-list="false"
                :action="imgHttpUrl"
                :on-success="handleAvatarSuccessweedit"
                list-type="picture-card"
                :on-exceed="handleExceed"
                  :headers="header"
                :data="multipartFile"
              >
              <img v-if="ruleFormd.weChatQrCode" :src="ruleFormd.weChatQrCode"/>
                <i v-else class="el-icon-plus"></i>
              </el-upload>
              </el-form-item>
            </div>
            <!-- <div v-if="ruleFormd.supplierId != 'null'">
              <el-form-item label="供应商" prop="personalintroduction">
                <el-select
                  disabled
                  style="width: 150px"
                  v-model="ruleFormd.supplierId"
                  placeholder="选择供应商"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in gyslist1"
                    :key="index"
                    :label="item.supplierName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div> -->
            <!-- <div class="form_item">
              <el-form-item label="员工简介" prop="personalintroduction">
                <el-input
                  style="width: 400px"
                  v-model="ruleFormd.personalintroduction"
                ></el-input>
              </el-form-item>
            </div> -->
            <div class="form_item">
              <el-form-item label="备注" prop="employeeMemo">
                <el-input style="width: 400px" v-model="ruleFormd.employeeMemo">
                </el-input>
              </el-form-item>
            </div>
            <el-form-item>
              <el-button
                style="background-color: #f6b23e; color: #fff; width: 110px"
                @click="RegulaChange"
                >确认
              </el-button>
              <el-button
                type="primary"
                style="width: 110px"
                @click="editjobs = false"
                >取消
              </el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
        <!-- 资源分配弹窗 -->
        <el-dialog
          title="资源转移"
          center
          :visible.sync="resourcedialogVisible"
          width="30%"
        >
          <el-form ref="form" :model="resourceDate" label-width="100px">
            <!-- <el-form-item label="资源类型：">
                   <el-select v-model="resourceDate.a" placeholder="请选择活动区域" size="mini">
                    <el-option label="新会员" value="newCustmer"></el-option>
                    <el-option label="老会员" value="oldCustmer"></el-option>
                  </el-select>
            </el-form-item> -->
              <el-form-item label="转移类型：">
                   <el-select v-model="resourceDate.updType" placeholder="请选择活动区域" size="mini" @change="zhuanyiChang">
                    <el-option label="全部转移" value="transferAll"></el-option>
                    <el-option label="单个转移" value="transferOne"></el-option>
                  </el-select>
            </el-form-item>
             <el-form-item label="会员ID:">
              <!-- <el-input v-model="resourceDate.customerId"  :disabled="resourceDate.b != 'one'" size="mini" style="width:200px"></el-input> -->
               <el-select
               :disabled="resourceDate.updType != 'transferOne'"
                v-model="resourceDate.customerId"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in userBOS"
                  :key="item.id"
                  :label="item.userName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="转移给：">
              <el-select
                v-model="resourceDate.targetId"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in memerList"
                  :key="item.id"
                  :label="item.adminName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="转移数量：">
              <el-input v-model="resourceDate.c" size="mini" style="width:200px"  :disabled="resourceDate.b != 'all'"></el-input>
            </el-form-item>-->
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="resourcedialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="getchangeVipresource()"
              >确 定</el-button
            >
          </span>
        </el-dialog>
        <!-- 资源回收弹窗 -->
        <el-dialog
          title="资源回收"
          center
          :visible.sync="resourceRetrievedialogVisible"
          width="30%"
        >
          <el-form :model="resourceform">
            <el-form-item label="">
              <el-radio-group v-model="resourceform.chooseAll" @change="huishouChang">
                <el-radio label="recycleAll">全部回收</el-radio>
                <el-radio label="recycleOne">单个回收</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              label="会员手机号"
              v-if="resourceform.chooseAll == 'recycleOne'"
            >
              <el-select
                v-model="resourceform.custmorPhone"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in userBOShuishou"
                  :key="item.id"
                  :label="item.userName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="resourceRetrievedialogVisible = false"
              >取 消</el-button
            >
            <el-button type="primary" @click="getreturnVipResource"
              >确 定</el-button
            >
          </span>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "department",
  data() {
    return {
imgHttpUrl:this.$imgHttpUrl,

      baseURL:localStorage.getItem('baseUrl'),
      //回收会员数组
      userBOShuishou:[],
      // 会员数组
      userBOS:[],
      // 图片请求头
      multipartFile:{type: "adminHead"},
      header:{
        token:localStorage.getItem('Xd_Token'),
      },
      
      
      vipviperwei:"",
      resourceform: {
        chooseAll: "",
        custmorPhone: "",
      },
      // 资源分配数据
      resourceDate: {
        updType:'',
        sourceId: "",
        targetId: "",
        customerId:""
      },
      // 资源分配弹窗
      resourcedialogVisible: false,
      // 资源回收弹窗
      resourceRetrievedialogVisible: false,
      // 在职的vip经理
      memerList: [],

      // 供应商列表
      gyslist1: [],
      employeePositions: [],
      pageSize: 10,
      currentPage: 1,
      pageNum: 10,
      // 文件上传
      imageUrl: "",
      updateimageUrl:"",
      weChatQrCode:'',
      updateweChatQrCode:'',
      positionNameDataList: [],
      // 职位下拉列表
      positionNameData: [],
      // vip经理级别
      viplevelList: [
        {
          value: "primary",
          label: "初级",
        },
        {
          value: "intermediate",
          label: "中级",
        },
        {
          value: "senior",
          label: "高级",
        },
        {
          value: "veteran",
          label: "资深",
        },
      ],
      data: [],
      defaultProps: {
        children: "list",
        label: "deptName",
        value: "deptId:",
        checkStrictly: true,
      },
      total: 0, // 多少条数据
      employees: [],
      radio: "",
      list: [],
      // departure:false,
      dialogVisible: false,
      editjobs: false,
      dialog: false,
      formInline: {
        employeeMobile: "",
        employeeLoginId: "",
        employeeName: "",
        deptId: "",
      },
      dialogImageUrl: "",
      //新增
      ruleForm: {
        manager: 'no',
        personalintroduction: "",
        employeeMobile: "",
        positionId: [],
        avatarUrl: "",
        deptId: "",
        employeeLoginId: "",
        employeeLoginPwd: "",
        employeeName: "",
        employeeIdno: "",
        employeeSex: "男",
        employeeMemo: "",
        isused: "yes",
        resourcelevel: null,
        resourcemaxlimitnum: "",
        othername: "",
        employeeBirthday: "",
        // deptName:"",
        gongyings: false,
        supplierId: "", //供应商id
        managerPhone: "",
      },
      ruleFormd: {
        manager: 'no',
        personalintroduction: "",
        employeeMobile: "",
        positionId: [],
        avatarUrl: "",
        deptId: null,
        employeeLoginId: "",
        employeeLoginPwd: "",
        employeeName: "",
        employeeIdno: "",
        employeeSex: "男",
        employeeMemo: "",
        isused: "yes",
        resourcelevel: null,
        resourcemaxlimitnum: "",
        othername: "",
        employeeId: "",
        employeeBirthday: "",
        supplierId: "", //供应商id
        managerPhone: "",
        imageUrl:'',
        updateimageUrl:'',
        weChatQrCode:'',
        updateweChatQrCode:''
      },
      dialogVisible: false,
      a: [],
      // 用来判断是不是vip经理
      a: "",
      positionName: "",
      // 搜索员工
      formInline: {
        pageNum: 1,
        pageSize: 10,
        deptId: "",
        employeeName: "",
        employeeLoginId: "",
        employeeMobile: "",
        employeeBirthday: "",
      },
      // 下拉部门列表的合集
      dropDownList: [],
      // vip经理id
      VipResourceEmployeeId: "",
    };
  },
  methods: {
    // 资源转移按钮
    resourceAllocationbtn(index, row) {
      this.userBOS = []
      this.resourcedialogVisible = true;
      this.userBOS = row.userBOS
      this.resourceDate.sourceId =row.id
    },
    // 资源回收按钮
    resourceretrievebtn(row) {
      console.log(row.id);
      this.VipResourceEmployeeId = row.id;
      this.userBOShuishou = row.userBOS;
      this.resourceRetrievedialogVisible = true;
    },
    // 点击回收事件
    huishouChang(row){
      if(row =="recycleAll"){
        this.resourceform.custmorPhone = ""
      }
    },
    handleNodeClick(data) {
      console.log(data);
    },

    // vip资源转移
    getchangeVipresource() {
      this.$axios.getchangeVipresource({
       updType:this.resourceDate.updType,
       fromAdminId:String(this.resourceDate.sourceId),
       userId:String(this.resourceDate.customerId),
       toAdminId:String(this.resourceDate.targetId)
      }).then((res) => {
        console.log(res);
        if (res.code == "00000") {
           this.postslist();
           this.$message({
          message: res.msg,
          type: 'success'
        });
          this.resourcedialogVisible = false

           this.resourceDate.updType=''
           this.resourceDate.sourceId=''
           this.resourceDate.customerId=''
        this.resourceDate.targetId=''
        }
      });
    },
    seachBtn() {
    this.formInline.pageNum =1,
        this.formInline.pageSize=10,
      this.postslist();
    },
    // 资源回收
    getreturnVipResource() {
      this.$axios
        .getchangeVipresource({
          fromAdminId:String(this.VipResourceEmployeeId),
          updType:this.resourceform.chooseAll,
          userId:String(this.resourceform.custmorPhone)
        })
        .then((res) => {
          console.log(res);
          if (res.code == "00000") {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.resourceRetrievedialogVisible = false;
            this.resourceform.custmorPhone =''
            this.postslist();
          }
        });
    
    },

    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },

    // 重置
    reset() {
      this.formInline.deptId = "";
      this.formInline.employeeName = "";
      this.formInline.employeeLoginId = "";
      this.formInline.employeeMobile = "";
      this.formInline.pageNum=1,
       this.formInline.pageSize=10,
      // 搜索部门
      this.postslist();
    },
    //分页
    handleSizeChange(value) {
       this.formInline.pageSize=value,
      this.postslist();
    },
    handleCurrentChange(value) {
     ;
      this.formInline.pageNum=value,
      this.postslist();
    },
    // 点击确定或者×后清空文档
    add() {
      this.imageUrl = "";
      this.updateimageUrl = "";
      this.weChatQrCode = ''
      this.updateweChatQrCode = '',
      
      this.ruleForm = {
        manager: 'no',
        personalintroduction: "",
        employeeMobile: "",
        positionId: [],
        avatarUrl: "",
        deptId: null,
        employeeLoginId: "",
        employeeLoginPwd: "",
        employeeName: "",
        employeeIdno: "",
        employeeSex: "",
        employeeMemo: "",
        isused: "yes",
        resourcelevel: null,
        resourcemaxlimitnum: "",
        othername: "",
        managerPhone: "",
      };
    },
    // 新增添加员工
    postsadds() {
      let arr = []
        arr = this.ruleForm.positionId.map((item) => {
            return{id:item}
        });
        console.log(arr)
      let arr2 = 
        {
          // 员工手机号1
          adminPhone: this.ruleForm.employeeMobile,
          // 职位表id1
          sysRoleBOList: arr,
          // 员工部门id1
          deptId: String(this.ruleForm.deptId),
          // 员工登录账号1
          adminNumber: this.ruleForm.employeeLoginId,
          // 员工登录密码1
          adminPassword: this.ruleForm.employeeLoginPwd,
          // 员工姓名1
          adminName: this.ruleForm.employeeName,
          // 是否使用1
          status: this.ruleForm.isused,
          // 员工身份证1
          adminCard: this.ruleForm.employeeIdno,
          // 员工性别 male男  female女1
          adminSex: this.ruleForm.employeeSex == "女" ? "女" : "男",
          //  是否vip经理1
          isManager: this.ruleForm.manager,
          //  员工简介
          adminIntroduce: this.ruleForm.personalintroduction,
          //  员工头像图片
          wechatQrcode:this.updateweChatQrCode,
          adminHead: this.updateimageUrl,
          //  员工备注1
          remark: this.ruleForm.employeeMemo,
          //  VIP级别1
          managerLevel: this.ruleForm.resourcelevel,
          //  最大上限2
          // resourcemaxlimitnum: this.ruleForm.resourcemaxlimitnum,
          //  昵称2
          // othername: this.ruleForm.othername,
          //经理电话1
          managerPhone: this.ruleForm.managerPhone,
          adminBirthday: this.ruleForm.employeeBirthday,

          // 员工部门头像
          // deptName: this.ruleFormd.deptName,
          // positionName: this.ruleFormd.positionName,
          // supplierId: Number(this.ruleForm.supplierId),
        }
      

      this.$axios.postsadd(arr2).then((res) => {
        this.postslist();
        console.log(res);
        if (res.code == "00000") {
      this.dialogVisible = false;

          this.$message({
            message: "新增成功",
            type: "success",
          });
        }
      });
    },
    // 员工职位下拉列表
    getworkAll() {
      this.$axios.getrolealist({
        pageNo:"1",
        pageSize:"99999"
      }).then((res) => {
        console.log(res);
        if (res.code == "00000") {
          this.positionNameDataList = res.data.records
        }
      });
    },
    // 在职的vip经理
    getselectEmployeeVip() {
      this.$axios.getselectEmployeeVip({}).then((res) => {
        console.log(res);
        if (res.code == "00000") {
          this.memerList = res.data;
        }
      });
    },
      vipviperweimahandleAvatarSuccess(res, file) {
        console.log(res, file)
        this.vipviperwei = res[0]
      },
    // 编辑时显示当前内容
    editjob(row) {
      this.editjobs = true;
     
      console.log(row);
      this.AdminUserInfoid = row.id
      this.$axios.getAdminUserInfo({
        id:String(row.id)
      }).then((res)=>{
        console.log(res);
         if (res.code == "00000") {
          this.ruleFormd.isused=res.data.status
          this.ruleFormd.employeeMemo=res.data.remark
          this.ruleFormd.manager=res.data.isManager
          this.ruleFormd.deptId=res.data.deptInfo.deptId
          this.ruleFormd.employeeBirthday=res.data.adminBirthday
          this.ruleFormd.employeeMobile=res.data.adminPhone
          this.ruleFormd.employeeLoginId=res.data.adminNumber
          this.ruleFormd.employeeLoginPwd=res.data.adminPassword
          this.ruleFormd.employeeName=res.data.adminName
          this.ruleFormd.resourcelevel=res.data.managerLevel
          this.ruleFormd.managerPhone=res.data.managerPhone
          this.ruleFormd.employeeIdno= res.data.adminCard
          this.ruleFormd.employeeSex= res.data.adminSex
          this.ruleFormd.updateimageUrl   = res.data.adminHead
          // this.ruleFormd.imageUrl   =this.baseURL + res.data.adminHead
          // this.ruleFormd.weChatQrCode=this.baseURL + res.data.wechatQrcode
           this.ruleFormd.imageUrl   = res.data.adminHead
          this.ruleFormd.weChatQrCode= res.data.wechatQrcode
          this.ruleFormd.updateweChatQrCode= res.data.wechatQrcode
          let arr= []
            for (let i = 0; i < res.data.sysRoleBOList.length; i++) {
              arr.push(res.data.sysRoleBOList[i].id)
            }
          this.ruleFormd.positionId = arr
        }
      })
    },
    // 修改员工
    Modifyemployee() {
      let arr = this.ruleFormd.positionId;
      // console.log(arr)
      let arr1 = [];
      for (let key of arr) {
        // console.log(key,arr[key])
        let obj = {
          id: key,
        };
        arr1.push(obj);
      }
      console.log(arr1);
      let arr4 = 
        {
          id:this.AdminUserInfoid,
          // 员工手机号1
          adminPhone: this.ruleFormd.employeeMobile,
          // 职位表id1
          sysRoleBOList: arr1,
          // 员工部门id1
          deptId: String(this.ruleFormd.deptId),
          // 员工登录账号1
          adminNumber: this.ruleFormd.employeeLoginId,
          // 员工姓名1
          adminName: this.ruleFormd.employeeName,
          // 是否使用1
          status: this.ruleFormd.isused,
          // 员工身份证1
          adminCard: this.ruleFormd.employeeIdno,
          // 员工性别 male男  female女1
          adminSex: this.ruleFormd.employeeSex,
          adminPassword:this.ruleFormd.employeeLoginPwd,
          //  是否vip经理
          isManager: this.ruleFormd.manager,
          //  员工简介
          // personalintroduction: this.ruleFormd.personalintroduction,
          //  员工头像图片
          adminHead: this.ruleFormd.updateimageUrl,
          //  员工备注
          remark: this.ruleFormd.employeeMemo,
          //  VIP级别
          managerLevel: this.ruleFormd.resourcelevel,
          //  最大上限
          // resourcemaxlimitnum: Number(this.ruleFormd.resourcemaxlimitnum),
          //  昵称
          // othername: this.ruleFormd.othername,
          // employeeId:this.ruleFormd.employeeId
          // employeeId: this.ruleFormd.employeeId,
          // 修改员工
          adminBirthday: this.ruleFormd.employeeBirthday,
          managerPhone: this.ruleFormd.managerPhone,
          wechatQrcode:this.ruleFormd.updateweChatQrCode,
        }
      
      console.log(arr4)
      this.$axios.gettedit(arr4).then((res) => {
        console.log(res);
        if (res.code == "00000") {
      this.dialogVisible = false;

          this.postslist();
          this.$message({
            message: "修改成功",
            type: "success",
          });
        }
        this.editjobs = false;
      });
    },
    // 搜索员工
    postslist() {
      this.$axios
        .postslist({
          //部门id
          deptId: this.formInline.deptId,
          //员工姓名
          adminNickName: this.formInline.employeeName,
          //员工工号
          adminNumber: this.formInline.employeeLoginId,
          //员工手机号
          adminPhone: this.formInline.employeeMobile,
          pageNo: this.formInline.pageNum,
          pageSize: this.formInline.pageSize,
          // employeeBirthday: this.formInline.employeeBirthday,
        })
        .then((res) => {
          console.log(res);
          if (res.code == "00000") {
            // 分页
            this.total = res.data.total;
            // 列表数据
            this.employees = res.data.records;
            for (let i = 0; i < res.data.records.length; i++) {
              this.employees[i].ancestors = res.data.records[i].deptInfo.ancestors
            }
          }
        });
    },
    // 重置密码
    // password(index, a) {
    //   console.log(index, a);
    //   this.$axios
    //     .getresetPassowrd({
    //       employeeId: a.employeeId,
    //     })
    //     .then((res) => {
    //       console.log(res);
    //       if (res.code == "200") {
    //         this.$message({
    //           message: "重置密码成功",
    //           type: "success",
    //         });
    //       }
    //     });
    // },

    // 员工离职复职
    getquit(index, row) {
      console.log(index, row);
       this.$axios.gettedit({
          id:String(row.id),
          status:row.status =="yes"?'no':'yes'
       }).then((res) => {
        console.log(res);
        if (res.code == "00000") {
          this.postslist();
          this.$message({
            message: "修改成功",
            type: "success",
          });
        }
      });

      // this.$axios
      //   .getquit({
      //     employeeId: a.employeeId,
      //   })
      //   .then((res) => {
      //     console.log(res);
      //     if (res.code == "200") {
      //       this.$message({
      //         message: "操作成功",
      //         type: "success",
      //       });
      //       this.postslist();
      //       this.getAllDepartment();
      //     }
      //   });
    },
    // 查询员工部门
    getAll() {
      this.$axios.getgetAll({}).then((res) => {
        console.log(res);
        let chirden = JSON.parse(JSON.stringify(res.data));
        console.log(chirden);
        if (res.code == "200") {
          this.data = chirden;
          console.log(this.data);
        }
      });
    },
    // L 查询所有员工部门
    getAllDepartment() {
      this.$axios.getDeptListAllList({
        status:"yes"
      }).then((res) => {
        if (res.code == "00000") {
          console.log(res);
          this.dropDownList = res.data;
        }
      });
    },
    zhuanyiChang(index){
      console.log(index)
      if(index == "transferAll"){
        this.resourceDate.customerId = ''
      }
    },
    // job(index,a){
    //   console.log(index,a)
    //   this.dialog=true
    // },
    // 添加员工的时候 上传的头像
    handleAvatarSuccess(res, file) {
      this.imageUrl =this.baseURL + res.data[0];
      this.updateimageUrl = res.data[0]
      console.log(res, file, this.imageUrl);
    },

    handleAvatarSuccesswe(res, file) {
      this.weChatQrCode =this.baseURL + res.data[0];
      this.updateweChatQrCode = res.data[0];
      console.log(res, file, this.weChatQrCode);
    },
       handleAvatarSuccessedit(res, file) {
      this.ruleFormd.imageUrl =this.baseURL + res.data[0];
      this.ruleFormd.updateimageUrl = res.data[0];
      
      console.log(res, file, this.imageUrl);
    },
    handleAvatarSuccessweedit(res, file) {
      this.ruleFormd.weChatQrCode =this.baseURL + res.data[0];
      this.ruleFormd.updateweChatQrCode = res.data[0];
      console.log(res, file, this.ruleFormd.weChatQrCode);
    },

    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
    },

    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      const isSize = new Promise(function (resolve, reject) {
        let width = 750;
        let height = 520;
        let _URL = window.URL || window.webkitURL;
        let img = new Image();
        img.onload = function () {
          console.log(img.width, img.height, "cccc");
          let valid = img.width == width && img.height == height;
          valid ? resolve() : reject();
        };
        img.src = _URL.createObjectURL(file);
      }).then(
        () => {
          return file;
        },
        () => {
          this.$message({
            message: "请上传尺寸为750*520的图片!",
            type: "error",
          });
          return Promise.reject();
          return false; //必须加上return false; 才能阻止
        }
      );
      return isJPG && isLt2M;
    },
    // 上传头像
    // getupload() {
    //   console.log(this.imageUrl);
    //   this.$axios
    //     .getupload({
    //       file: this.imageUrl.split(0, 4),
    //     })
    //     .then((res) => {
    //       console.log(res);
    //       if (res.code == "200") {
    //       }
    //     });
    // },

    getupload() {
      this.$axios
        .getupload({
          file: this.dialogImageUrl,
        })
        .then((res) => {
          console.log(res);
          if (res.code == "200") {
          }
        });
    },

    // 新增正则验证
    RegulaNew() {
      let regpassWord = /^[0-9A-Za-z]{6,}$/g;

      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (!reg.test(this.ruleForm.employeeMobile)) {
        this.$confirm("请输入正确的电话", "提示", {
          confirmButtonText: "确定",
          type: "warning",
        });
      } else {
        if (!regpassWord.test(this.ruleForm.employeeLoginPwd)) {
          this.$confirm("请输入六位以上密码", "提示", {
            confirmButtonText: "确定",
            type: "warning",
          });
        } else {
          this.postsadds();
        }
      }
    },
    // 修改正则验证
    RegulaChange() {
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (!reg.test(this.ruleFormd.employeeMobile)) {
        this.$confirm("请输入正确的电话", "提示", {
          confirmButtonText: "确定",
          type: "warning",
        });
      } else {
        this.Modifyemployee();
      }
    },
    //供应商列表
    getsupplier(id) {
      // console.log(id);
      localStorage.setItem("isToken", true);
      this.$axios.getsupplier({}).then((res) => {
        this.gyslist1 = res.data;
      });
      
    },
  },

  mounted() {
    console.log(document.cookie.split('; ')[0].split('=')[1])
    this.getAllDepartment();

    // 搜索部门
    this.postslist(),
      // 查询员工部门
      this.getAll();
    // 查询所有员工部门
    // this.getAllDepartment();
    // 职位下拉
    this.getworkAll();
    // 供应商列表
    this.getsupplier();
    // 查询在职的vip经理
    this.getselectEmployeeVip();
  },
};
</script>
<style scoped>
.department {
  height: 100%;
  background-color: #f7f7f7;
  padding-bottom: 70px;
}
.form_item {
  display: flex;
}
.header-1-1 {
  font-weight: bolder;
  display: flex;
  margin-left: 20px;
  padding-top: 20px;
}
.header-1-1-1 {
  font-weight: bolder;
  display: flex;
  margin-left: 20px;
}
.tou {
  width: 3.5px;
  height: 17px;
  background-color: #4b71bf;
  margin-top: 2px;
  margin-right: 4px;
  font-size: 12px;
  margin-bottom: 25px;
}
.tuo {
  font-weight: bolder;
  display: flex;
  margin-left: 20px;
  padding-top: 20px;
  justify-content: space-between;
  margin-right: 20px;
}
.tuo-1 {
  display: flex;
}
.tuo-2 {
  width: 3.5px;
  height: 17px;
  background-color: #4b71bf;
  margin-top: 2px;
  margin-right: 4px;
  font-size: 12px;
  margin-bottom: 25px;
}
.invoice-9 {
  font-size: 11px;
}
.invoice {
  width: 97%;
  margin: auto;
  display: flex;
  height: 44px;
  margin-bottom: 20px;
  min-width: 1200px;
}
.invoice-1 {
  margin-right: 20px;
}
.invoice-2 {
  margin-left: 20px;
}
.hackhome {
  border-top: 1px solid #e0e0e0;
  width: 98%;
  margin-left: 20px;
}
.table {
  margin-left: 20px;
  margin-right: 20px;
}
.top-6 {
  display: flex;
}
.tou-3 {
  display: flex;
}
#selectForm >>> .el-form-item__label {
  font-size: 11px;
}
.pop-9 {
  font-size: 11px;
  width: 120px;
  padding-top: 5px;
}
.pop {
  margin-left: 20px;
}
.pop-1 {
  width: 400px;
}
.pop-1-2 {
  display: flex;
  margin-bottom: 20px;
}
.pop-3 {
  margin-left: 20px;
  margin-top: 40px;
}
.form {
  margin-left: 20px;
}
.cell {
  display: flex;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.upload {
  margin-left: 25px;
  font-size: 12px;
  margin-bottom: 5px;
  margin-top: 32px;
}
.upload_box {
  display: flex;
}
.block {
  margin-left: 20px;
  padding-bottom: 20px;
  margin-top: 10px;
  float: right;
}
::v-deep  .el-upload--picture-card {
  display: flex;
  align-items: center;
    justify-content: center;
}
 .el-upload--picture-card > img {
  width: 100%;
  height: 100%;
}
.cen_head {
  display: flex;
  margin-bottom: 20px;
}
 
</style>
